<template>
  <el-container class='Main-box'>
    <el-header>
      <h1>电商后台管理系统</h1>
      <el-button @click='back'>退出</el-button>
    </el-header>
    <el-container class='content'>
      <el-aside :width="collapse ? '64px' : '200px'">
        <div class='main-aside-title' @click='collapse = !collapse'> | | | </div>
         <el-menu
          :default-active="activeItem"
          background-color="rgb(156, 255, 230)"
          text-color="rgb(129, 77, 16)"
          :collapse-transition='false'
          router
          :collapse='collapse'
          unique-opened
          active-text-color="rgb(56, 167, 99)"
          @select='select'>
          <el-submenu :index='i.path' v-for='i in Menus' :key='i.id'>
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{ i.authName }}</span>
            </template>
            <el-menu-item :index='"/" + j.path' v-for='j in i.children' :key='j.id'>
               <template slot="title">
                <i class="el-icon-location"></i>
                <span>{{ j.authName }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      Menus:[],
      collapse : false,
      activeItem : this.$route.path,
    }
  },
  methods: {
    async getMenus() {
      let res = await this.axios.get('/menus')
      if( res.meta.status !== 200 ) return this.pop.error( res.meta.msg )
      this.Menus = res.data
    },
    back() {
      window.sessionStorage.clear()
      this.$router.push('/login')
      this.pop.success('退出成功')
    },
    select(index) {
      this.activeItem = index
    }
  },
  created() {
    this.getMenus()
  }
}
</script>

<style scoped>
.el-header {
  background: rgb(56, 167, 99);
  background: rgba(10, 166, 214, 0.712);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.el-header h1 {
  color:rgb(255, 255, 255);
}
.el-aside {
  background: rgba(10, 166, 214, 0.712);
  overflow: hidden;
}
.main-aside-title {
  width:100%;
  text-align: center;
  line-height: 2;
}
.el-menu-item {
  text-align:center;
}
.Main-box {
  height:100%;
  box-sizing: border-box;
}
.content {
  height:calc(100% - 65px);
}
.el-main {
  height:100%;
  box-sizing: border-box;
}
</style>